home *** CD-ROM | disk | FTP | other *** search
- Path: fred.net!news
- From: bitmask@bigdog.fred.net (Scott Allen)
- Newsgroups: comp.lang.c++
- Subject: Re: Persistent Objects
- Date: Wed, 20 Mar 1996 12:55:32 GMT
- Organization: FredNet - Frederick, Md.
- Message-ID: <314f0632.13262854@news.fred.net>
- References: <4i50ja$2lu@atlantis.cc.uwf.edu> <4if2op$578@sam.inforamp.net>
- NNTP-Posting-Host: bitmask.fred.net
- X-Newsreader: Forte Agent .99d/32.168
-
- rmorin@inforamp.net (Randy Charles Morin) wrote:
- >
- >class PersistentObject
- >{
- >private:
- > int i;
- >public:
- > PersistentObject();
- > ~PersistentObject();
- >};
- >
- >PersistentObject::PersistentObject()
- >{
- > ifstream is(FILENAME.EXT);
- > is >> i;
- >}
- >
- >PersistentObject::~PersistentObject()
- >{
- > ofstream os(FILENAME.EXT);
- > os << i;
- >}
- >
- >A very simplistic example.
-
- I just wanted to add to Randy's example a little bit.
-
- A better implementation of a persistant object would
- use the chainable << and >> operators to allow
- you to save your objects in a stream. You could then
- steam multiple objects into a file on disk,
- into memory, over a modem etc. etc.
-
- The above code would have a little bit of problem
- if a class is instantiated more than once.
- --
- Scott Allen
- bitmask@bigdog.fred.net
- Hagerstown, MD USA
-